/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.portlet.editor.visitor;

import java.util.Map;
import java.util.TreeMap;

import com.genia.toolbox.basics.exception.BundledException;
import com.genia.toolbox.web.portlet.bean.Portlet;
import com.genia.toolbox.web.portlet.bean.impl.ContainerPortlet;
import com.genia.toolbox.web.portlet.bean.impl.DispatcherPortlet;
import com.genia.toolbox.web.portlet.bean.impl.HolePortlet;
import com.genia.toolbox.web.portlet.bean.impl.LinkedPortlet;
import com.genia.toolbox.web.portlet.bean.impl.SimplePortlet;
import com.genia.toolbox.web.portlet.bean.impl.TemplatePortlet;
import com.genia.toolbox.web.portlet.visitor.PortletVisitor;

/**
 * Retrieve all the holes from a template.
 */
public class HolesPortletVisitor
    implements PortletVisitor
{

  /**
   * The holes.
   */
  private Map<String, String> holes;



  /**
   * Constructor.
   */
  public HolesPortletVisitor()
  {
    super();
    this.holes = new TreeMap<String, String>();
  }



  /**
   * the visitor method for a <code>ContainerPortlet</code>.
   * 
   * @param portlet
   *          the <code>ContainerPortlet</code> begin visited
   * @throws BundledException
   *           if an error occured
   */
  public void visitContainerPortlet(ContainerPortlet portlet)
      throws BundledException
  {
    for (Portlet subPortlet : portlet.getSubPortlets()) {
      subPortlet.visit(this);
    }
  }



  /**
   * the visitor method for a <code>DispatcherPortlet</code>.
   * 
   * @param portlet
   *          the <code>DispatcherPortlet</code> begin visited
   * @throws BundledException
   *           if an error occured
   */
  public void visitDispatcherPortlet(DispatcherPortlet portlet)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * the visitor method for a <code>HolePortlet</code>.
   * 
   * @param portlet
   *          the <code>HolePortlet</code> begin visited
   * @throws BundledException
   *           if an error occured
   */
  public void visitHolePortlet(HolePortlet portlet)
      throws BundledException
  {
    this.holes.put(portlet.getHoleName(), "");
  }



  /**
   * the visitor method for a <code>LinkedPortlet</code>.
   * 
   * @param portlet
   *          the <code>LinkedPortlet</code> begin visited
   * @throws BundledException
   *           if an error occured
   */
  public void visitLinkedPortlet(LinkedPortlet portlet)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * the visitor method for a <code>SimplePortlet</code>.
   * 
   * @param portlet
   *          the <code>SimplePortlet</code> begin visited
   * @throws BundledException
   *           if an error occured
   */
  public void visitSimplePortlet(SimplePortlet portlet)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * the visitor method for a <code>TemplatePortlet</code>.
   * 
   * @param portlet
   *          the <code>TemplatePortlet</code> begin visited
   * @throws BundledException
   *           if an error occured
   */
  public void visitTemplatePortlet(TemplatePortlet portlet)
      throws BundledException
  {
    // Do nothing.
  }



  /**
   * Get the holes.
   * 
   * @return the holes.
   */
  public Map<String, String> getHoles()
  {
    return this.holes;
  }



  /**
   * Reset the list.
   */
  public void reset()
  {
    this.holes.clear();
  }

}
